#include "opencv2/opencv.hpp"
using namespace cv;

#include <iostream>
#include <sstream>
using namespace std;

void help()
{
	cout
	<< "--------------------------------------------------------------------------" << endl
	<< "This program shows you how to read and extract frame from a video file" << endl
	<< "Usage:" << endl
	<< "./FramesGrabbing inputvideoName" << endl
	<< "--------------------------------------------------------------------------" << endl
	<< endl;
}

int main(int argn, char* argv[])
{
	help();

	if (argn < 2)
	{
		cout << "Not enough parameters" << endl;
		return -1;
	}

	VideoCapture cap(argv[1]); // open the default camera
	if(!cap.isOpened())  // check if we succeeded
	{
		cout << "The video" << argv[1] << " could not be loaded." << endl;
		return -1;
	}
	
	namedWindow("edges", CV_WINDOW_AUTOSIZE);

	for(;;)
	{
		Mat frame;
		Mat edges;
		if (!cap.read(frame)) break; // get a new frame from camera
		cvtColor(frame, edges, CV_BGR2GRAY);
		GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
		Canny(edges, edges, 0, 30, 3);
		imshow("edges", edges);
		if(waitKey(30) >= 0) break;		
	}
	
	// the camera will be deinitialized automatically in VideoCapture destructor
	return 0;
}